import java.lang.reflect.Array;
import java.util.Arrays;

public class code {
    public static void main(String[] args) {
        int [] array={1,2,3,4};
        int [] copy =Arrays.copyOf(array,array.length);
        System.out.println(Arrays.toString(copy));
    }

    //数组转字符串模拟实现
    public static String myToString(int [] array) {
        if(array==null)
            return "null";
        String ret ="[";
        for (int i = 0; i <array.length ; i++) {
            ret+=array[i];
            if(i!=array.length-1) {
                ret +=",";
            }
        }
        ret +="]";
        return ret;
    }
    public static void main3(String[] args) {
        int [] array ={1,2,3,4};
        String ret=myToString(array);
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        //遍历数组的三种方法
        int [] array={1,2,3,4};
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");//这里要用" "
        }
        System.out.println();
        for (int x:array) {
            System.out.print(x+" ");
        }
        System.out.println();

        String ret = Arrays.toString(array);
        System.out.println(ret);
    }
    public static void main1(String[] args) {
        //创建数组的三种方式：
        int [] array=null;
        int [] array2=new int [] {1,2,3,4};
        int [] array3=new int[10];
    }
}
